package com.sgcc.sx.pmos.e_sx_mall.fragment;

import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.sx.pmos.arouter.mall.MallArouterPath;
import com.sgcc.sx.pmos.common.base.MvpBaseRecycleFragment;
import com.sgcc.sx.pmos.common.bean.StoreInfoBean;
import com.sgcc.sx.pmos.common.utils.ListPageUtil;
import com.sgcc.sx.pmos.e_sx_mall.adapter.StoreAdapter;
import com.sgcc.sx.pmos.e_sx_mall.bean.StoreBean;
import com.sgcc.sx.pmos.e_sx_mall.contract.StoreSearchContract;
import com.sgcc.sx.pmos.e_sx_mall.presenter.StoreSearchPresenter;

/**
 * 店铺
 */
public class StoreSearchFragment extends MvpBaseRecycleFragment<StoreInfoBean, StoreSearchPresenter> implements StoreSearchContract.View {

    private StoreAdapter mStoreAdapter;
    private String searchContent;

    @Override
    protected StoreSearchPresenter createPresenter() {
        return new StoreSearchPresenter();
    }

    @Override
    public boolean setFloatingButtonVisibility() {
        return false;
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        mStoreAdapter = new StoreAdapter(mContext);
        mStoreAdapter.setOnItemClickListener(new StoreAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, StoreInfoBean bean) {
                ARouter.getInstance()
                        .build(MallArouterPath.MALL_STOREHOMEPAGE)
                        .withString("membersSdId", bean.getMembersSdId())
                        .navigation();
            }
        });
        return mStoreAdapter;
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mListSize = listSize;
        mPresenter.getStoreList(listSize, false, searchContent);
    }

    int mListSize;

    @Override
    public void querySuccess(StoreBean response) {
        if (response != null) {
            if (response.getCode() == 200) {
                if (response.getRows() != null) {
                    loadSuccess(ListPageUtil.isHasNextPage(response.getTotal(), mListSize), response.getRows());
                }
            } else {
                loadFalied();
            }
        }
    }

    @Override
    public void queryFailed() {
        loadFalied();
    }

    public void setSearchContent(String searchContent) {
        this.searchContent = searchContent;
        refresh(false);
    }
}
